<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>详单查询</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta content="telephone=no" name="format-detection" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta id="viewport" name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0,user-scalable=no,target-densitydpi=260">
<script src="js/jquery-1.8.0.min.js"></script>
<link rel="stylesheet" type="text/css" href="common.css">
<link rel="stylesheet" type="text/css" href="css/detail_query.css">
<script src="js/jquery.cookie.js"></script>
<script src="js/jquery.getparm.js"></script>
<script src="js/iScroll4.2.5-min.js"></script>
<link rel="stylesheet" type="text/css" href="home.css?version=0310">
<script type="text/javascript" src="js/common.js?version=0310"></script>
<script>
var vscroll;
var tabParam="banli";//初始化加载正在办理列表
var tabListId="operingContent"; //初始化加载正在办理列表
var tabIndex=($.getUrlParam("tabIndex")==null || $.getUrlParam("tabIndex")=="")?1:$.getUrlParam("tabIndex");
var op=$.getUrlParam("op");
var requestPage=$.getUrlParam("requestPage");
var selectlist="fanyong";
window.onload=function loaded(){

	if(tabIndex==1){
		//alert(1);
		$("#opering").trigger("click");
		if(op!=null && op!=""){
			setTimeout(function(){
				$("#listTitle"+tabIndex+"0").trigger("click");
			},100);
		}
	}else if(tabIndex==2){
		//alert(2);
		$("#sending").trigger("click");
	}else{
		//alert(3);
		$("#recresult").trigger("click");
	}

}

//$(document).bind('DOMContentLoaded', loaded, false);
var fid=$.cookie("NP_INFO_ID");
var ukey=$.cookie("U_KEY");
$(document).ready(function(e) {
	if(requestPage!=null && requestPage!=""){
		$(".menuTd").text("返回").click(function(){
			window.history.go(-1);
		});
	}

	initDiv();
	initData(tabParam);
	
});
function initDiv()
{
	$("#opering").addClass("tabSelect");
	$("#operingContent").show();
    $("#sending").addClass("tabNoSelect");
	$("#sendingContent").hide();
	$("#recresult").addClass("tabNoSelect");
	$("#recresultContent").hide();
}
/*tab切换效果*/
function tabModify(divId){
	$("#"+divId+"Content").height(1000);
	var tabArray=['opering','sending','recresult'];
	//切换数据
	initTabDatasByStep(divId);
	if($("#"+divId).attr("class")=="tab tabNoSelect"){
		$("#"+divId).removeClass("tabNoSelect").addClass("tabSelect");
		$("#"+divId+"Content").show();
		tabArray.splice($.inArray(divId,tabArray),1);
		$.each(tabArray,function(i,items){
			$("#"+items).removeClass("tabSelect").addClass("tabNoSelect");
			$("#"+items+"Content").hide();
		});
	}
		
}
function initTabDatasByStep(tabId){
	var stepResult="";
	switch(tabId){
		case "opering":
		tabParam="banli";
		tabIndex=1;
		break;
		case "sending":
		tabParam="paisong";
		tabIndex=2;
		break;
		case "recresult":
		tabParam="fanyong";
		tabIndex=3;
		break;
	}
	tabListId=tabId+"Content";
	tabParam=tabParam=="fanyong"?$("#sel_paisong").val():tabParam;
	initData(tabParam);
}
function listTitleModify(divId,date){
	if($("#"+divId).attr("class")=="listTitle"){
		//请求数据
		getListDatas(divId,date);
		$("#"+divId).removeClass("listTitle").addClass("listTitle_1");
		$("#"+divId+"_Detail").slideDown(800);
		//重新计算滑动区域高度
		$("#detailList").height($(window).height()-$("#header").height()-$("#selectTab").height()-50+$("#"+divId+"_Detail").height())
	}else{
		$("#"+divId).removeClass("listTitle_1").addClass("listTitle");
		$("#"+divId+"_Detail").slideUp(800);
		//重新计算滑动区域高度
		//$("#detailList").height($(window).height()-$("#header").height()-$("#selectTab").height()-50-$("#"+divId+"_Detail").height())
	}

}
function getListDatas(divId,date){
	tabParam=(tabParam=="fanyong"?selectlist:tabParam);
	$.natureajax({
			url:jsonserver+"orderinfo_mobileQueryOrderList.do?callback=?",//获取JSON
			data:"OI_NATURE_FID="+fid+"&BUSINESS_TYPE="+selectlist+"&Ukey="+ukey+"&OI_PREDEAL_DATE="+date,
			dataType:"jsonp",
			success:function(json){
				var resultCode=json[0].result;
				if(resultCode==1){
					var resultArray=json[1];
					$("#"+divId+"_Detail").children().remove();
					$.each(resultArray,function(i,items){
						
						var listOptionDiv="";
						if(i==resultArray.length-1){
							listOptionDiv=$("<div>").addClass("listOption lastListOption");
						}else{
							listOptionDiv=$("<div>").addClass("listOption");
						}
						var orderNo=items.OI_ORDER_NO;
						//var orderNo="TTTTTTTTTTTTTTTTTTTTTTTEEEEEEEEEEEEEEEEEEEEE";
						if(orderNo.length>30){
							orderNo=orderNo.substring(0,20);
							//alert(orderNo);
						}
						//alert(items.NOW_STATUS);
						var optionTable='<table width="100%" class="detailTable" onClick="requestDetail(\''+items.OI_ORDER_NO+'\',\''+items.OI_ORDER_NO+'\')">'+
										   '<tr>'+
											  '<td width="5%"></td>'+
											  //'<td >推荐号:<div>'+items.OI_ORDER_NO+'</div></td>'+
											  '<td >推荐号:<span>'+orderNo+'</span>&nbsp;&nbsp;&nbsp;&nbsp;'+items.NOW_STATUS+'</td>'+
											  '<td width="10%"></td>'+
											  '<td rowspan="3" width="10%"><img src="images/wo_list_jiantou.png"/></td>'+
											'</tr>'+
											'<td width="10%"></td>'+
											 '<td style="text-align:left">客户:'+items.OI_CUSTOMERNAME+'</td>'+
											  '<td></td>'+
											'</tr>'+
											'<tr>'+
											  '<td></td>'+
											  '<td >联系电话:<span>'+items.OI_SMCONTACTTEL+'</span></td>'+
											  '<td></td>'+
											'</tr>'+
										'</table>';
						listOptionDiv.append(optionTable);
						listOptionDiv.appendTo($("#"+divId+"_Detail"));
						
					});
					
				}
				
			},
			error:function(){
			alert("出错了!");
			}
			
		})
	
}
function initData(tp){
		
		selectlist=tp;
		$.natureajax({
			url:jsonserver+"orderinfo_getOrderCount.do?callback=?",//获取JSON
			data:"OI_NATURE_FID="+fid+"&BUSINESS_TYPE="+tp+"&Ukey="+ukey,
			dataType:"jsonp",
			success:function(json){
				$("#"+tabListId).children("div[id!=selDiv]").remove();
				$("#"+tabListId).children("br").remove();
				var resultCode=json[0].result;
				if(resultCode==1){
					
					var resultArray=json[1].data;
					if(resultArray.length>0){
						$.each(resultArray,function(i,items){
							var listTitle=$("<div>").attr("id","listTitle"+tabIndex+i).bind("click",function(){listTitleModify('listTitle'+tabIndex+i,items.OI_PREDEAL_DATE);})
									.addClass("listTitle").html('<img src="images/querydetail/query_flag.png" style="margin-left:5%; margin-right:50px;"/>'+items.OI_PREDEAL_DATE+'业务推荐单('+items.OI_PREDEAL_COUNT+')');
							listTitle.appendTo($("#"+tabListId));
							var titleDetailDiv=$("<div>").attr("id","listTitle"+tabIndex+i+"_Detail").addClass("listTitle_Detail");
							titleDetailDiv.appendTo($("#"+tabListId));
							$("<br>").appendTo($("#"+tabListId));
						});
					}else{
						$("#"+tabListId).append("<div style='text-align:center; font-size:28px;'>您目前没有推荐单</div>");
					}
				}
				
			},
			error:function(){
			alert("出错了!");
			}
			
		})

}
function selectChange(selectId){
	initData($("#"+selectId).val());
}
function requestDetail(recId,orderno){
	window.location.href="dingdanxq.html?OI_ID="+recId+"&order_no="+orderno;
}
</script>
</head>

<body>

<div id="header" class="header">
  <table width="100%" class="headerTal">
    <tr>
      <td class="menuTd">返回</td>
      <td style="font-size:38px; color:#fff; text-align:center"  align="center" >业务推荐单</td>
      <td width="20%"  align="center" ></td>
    </tr>
  </table>
</div>
<div id="selectTab">
  <div id="opering" class="tab" style="margin-left:3.5%;" onClick="tabModify('opering')">正在办理</div>
  <div id="sending" class="tab" onClick="tabModify('sending')">正在派送</div>
  <div id="recresult" class="tab" onClick="tabModify('recresult')">推荐结果</div>
</div>
<div id="detailList">
  <div id="warpper">
    <div id="operingContent">
      <div id="listTitle11" class="listTitle" onClick="listTitleModify('listTitle11')"><img src="images/querydetail/query_flag.png" style="margin-left:5%"/>2012/6/15 业务推荐单(2)</div>
      <div id="listTitle11_Detail" class="listTitle_Detail">
       
      </div>
      <br>
      <div id="listTitle12" class="listTitle" onClick="listTitleModify('listTitle12')"><img src="images/querydetail/query_flag.png" style="margin-left:5%"/></div>
      <div id="listTitle12_Detail" class="listTitle_Detail">
       
      </div>
    </div>
    <div id="sendingContent">
      <div id="listTitle2" class="listTitle" onClick="listTitleModify('listTitle2')"><img src="images/querydetail/query_flag.png" style="margin-left:5%"/></div>
      <div id="listTitle2_Detail" class="listTitle_Detail">
       
      </div>
    </div>
    <div id="recresultContent">
        <div style="margin-left:5%; width:90%; height:60px; margin-bottom:20px;" id="selDiv">
            <select style="width:100%;" id="sel_paisong"  onChange="selectChange('sel_paisong')" >
                <option value="fanyong">全部</option>
                <option value="sendsuccess">推荐成功</option>
                <option value="sendfailed">推荐失败</option>
            </select>
        </div>
      <div id="listTitle3" class="listTitle" onClick="listTitleModify('listTitle3')"><img src="images/querydetail/query_flag.png" style="margin-left:5%"/></div>
      <div id="listTitle3_Detail" class="listTitle_Detail">
        
      </div>
    </div>
  </div>
</div>
</body>
</html>
